<?php


namespace app\api\controller;


use app\common\controller\Api;

class MemberAppeal extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];


    /**
     * 发布诉求
     * @ApiMethod   (POST)
     * @param string $name 联系人
     * @param string $mobile 联系电话
     * @param string $content 诉求内容
     * @param string $images 诉求图片
     * @param int $is_open 公开:0=否,1=是
     */
    public function issueMemberAppeal(\app\common\model\MemberAppealModel $MemberAppealModel)
    {
        $user_id = $this->auth->id;
        $name = $this->request->request('name');
        $mobile = $this->request->request('mobile');
        $content = $this->request->request('content');
        $images = $this->request->request('images');
        $is_open = $this->request->request('is_open',0);
        if(empty($name) || empty($mobile) || empty($content) || empty($images)){
            $this->error('请求参数错误');
        }
        $data = $MemberAppealModel->issueMemberAppeal($user_id,$name,$mobile,$content,$images,$is_open);
        $this->result($data['msg'], $data['data'], $data['code']);
    }

    /**
     * 获取分页列表
     * @ApiMethod   (GET)
     * @param string $mold open=公开,my=我的
     * @param int $user_id
     * @param int $page
     * @param int $limit 数据条数
     */
    public function getPageList(\app\common\model\MemberAppealModel $MemberAppealModel)
    {
        $user_id = $this->auth->id;
        $mold = $this->request->request('mold','open');
        $page = $this->request->request('page',1);
        $limit = $this->request->request('limit',5);
        $data = $MemberAppealModel->getPageList($mold,$user_id,$page,$limit);
        $this->result($data['msg'], $data['data'], $data['code']);
    }

    /**
     * 评价
     * @ApiMethod   (POST)
     * @param int $id
     * @param int $user_id
     * @param int $star
     */
    public function evaluateMemberAppeal(\app\common\model\MemberAppealModel $MemberAppealModel)
    {
        $user_id = $this->auth->id;
        $id = $this->request->request('id');
        $star = $this->request->request('star');
        if(empty($id) || empty($star)){
            $this->error('请求参数错误');
        }
        $data = $MemberAppealModel->evaluateMemberAppeal($id, $user_id, $star);
        $this->result($data['msg'], $data['data'], $data['code']);
    }

}